import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {NzMessageService} from "ng-zorro-antd/message";
import {NzModalService} from "ng-zorro-antd/modal";
import { FeatureService } from 'src/app/shared/services/feature.service';
import {ConfigService} from "../../../shared/services/config.service";
import { LayerService } from '../layer/layer.service';


@Component({
    selector: 'app-feature',
    templateUrl: './feature.component.html',
    styleUrls: ['./feature.component.scss']
})
export class FeatureComponent implements OnInit {

    feature: any;
    layer: any;

    visible: boolean = false;


    constructor(public configService: ConfigService, private message: NzMessageService, private layerService: LayerService, private featureService: FeatureService) {
    }

    ngOnInit(): void {
        
    }


    /////////////////以下界面交互/////////////////////
    show(feature) {
        const layer = this.layerService.layers.find(item => item.name == feature.layer);
        this.visible = true;
        this.feature = feature;
        this.feature.properties = this.feature.properties || {};
        this.layer = layer;
    }

    close() {
        this.visible = false;
    }

    save() {
        this.featureService.update({
            _id: this.feature._id,
            properties: this.feature.properties
        }).subscribe(res => {
            if (res.result) {
                this.message.create('success', '保存成功！');
            } else {
                this.message.create('warning', '名称已存在！');
            }
        });
    }
}
